package lumis.service.wiki;

import lumis.doui.processaction.ProcessActionHandler;
import lumis.doui.source.ISourceData;
import lumis.doui.source.TabularData;
import lumis.doui.table.TableSource;
import lumis.portal.PortalException;


/**
 * Verifies if the article can be deleted. 
 * If the article is the main article, it cannot be deleted.
 * <p>
 * This Process Action throws a {@link PortalException} if
 * a selected article contains its <code>mainArticle</code> field a true value.
 *
 * @version $Revision: 10825 $ $Date: 2009-08-04 12:36:40 -0300 (Tue, 04 Aug 2009) $
 * @since 5.0.0
 */
public class ValidateArticleDeletionProcessActionHandler extends ProcessActionHandler<TableSource>
{
	public void processAction() throws PortalException
	{
		// read selected articles data
		String[] primaryKeyValues = (String[])getParameter("id");
		TabularData tabularData = source.readData(primaryKeyValues, transaction);
		
		// check if any article is a main article
		for (ISourceData row: tabularData.getRows())
		{
			boolean mainArticleValue = row.get("mainArticle", Boolean.class);
			if (mainArticleValue)
				throw new PortalException(localize("STR_CANNOT_DELETE_MAIN_ARTICLE"));
		}
	}
}
